﻿@{
	Layout = "~/Views/Shared/_ErrorLayout.cshtml";
	ViewBag.Title = "Page Not Found";
	ViewBag.Subtitle = "We may not be able to find the page, but perhaps you could help find one of these missing children...";
}

@*http://www.hanselman.com/blog/PutMissingKidsOnYour404PageEntirelyClientSideSolutionWithYQLJQueryAndMSAjax.aspx*@

@section Stylesheets
{
	<style type="text/css">
		body { text-align: center; }

		.missing-kid {
			padding-bottom: 20px;
			text-align: left;
		}

		.missing-kid img { margin-right: 10px; }

		.sys-template { display: none; }
	</style>
}

<div class="block">
	<div id="missing-kids" class="sys-template center">
		<div class="row missing-kid ">
			<div class="span12">
				<img sys:width="60" sys:align="left" sys:src="{binding medpic, convert=getSrc}" />
				<p><strong>{{firstname + " " + lastname}}</strong>, Age: {{age}} from {{city}}, {{st}}</p>
				<p>Contact: {{policeadd}} at {{policenum}}</p>
			</div>
		</div>
	</div>
</div>

@section Scripts
{

	<script src="http://ajax.microsoft.com/ajax/beta/0911/Start.js" type="text/javascript"></script>

	<script type="text/javascript">
	    Sys.require([Sys.components.dataView, Sys.scripts.jQuery], function() {
	        $("#missing-kids").dataView();

	        var stateCode = "ZZ";

	        if (navigator.geolocation) {
	            navigator.geolocation.getCurrentPosition(function(position) {
	                if (position.address) {
	                    stateCode = position.address.region;
	                }
	            }, function() {
	            });
	        }

	        var dataurl = "http://query.yahooapis.com/v1/public/yql?q=SELECT%20*%20From%20xml%0D%0A%20Where%20url%3D'http%3A%2F%2Fwww.missingkidsmap.com%2Fread.php%3Fstate%3D" + stateCode + "'%0D%0A&format=json&callback=?";
	        $.getJSON(dataurl, function(results) {
	            Sys.get("$missing-kids").set_data(results.query.results.locations.location);
	        });
	    });

	    function getSrc(url) {
	        var lastIndex = url.lastIndexOf('=');

	        return url.substring(lastIndex + 1);
	    }
	</script>

}